var dom = fw.getDocumentDOM(); var sel = [].concat(fw.selection); function DeleteOutside(){ if(!dom) return; var BOUNDS = {left:dom.left,top:dom.top,right:dom.left+dom.width,bottom:dom.top+dom.height}; var elems = [].concat(sel); // if no elements selected, use all elements in document if(!sel.length){ elems = []; for(var l in dom.layers){ for(var e in dom.layers[l].frames[dom.currentFrameNum].elements){ elems.push(dom.layers[l].frames[dom.currentFrameNum].elements[e]); } } } // delete obnjects outside of canvas var elem, remainingElems = []; for(var e in elems){ elem = elems[e]; if(elem.left+elem.width < BOUNDS.left || elem.left > BOUNDS.right || elem.top+elem.height < BOUNDS.top || elem.top > BOUNDS.bottom){ deleted = true; fw.selection = [elem]; dom.deleteSelection(false); }else{ remainingElems.push(elem); } } fw.selection = remainingElems; if(elems.length == remainingElems.length){ var note = sel.length ? 'No objects were found completely outside the canvas.' : 'Your selection did not contain any objects outside the canvas. Select objects outside the canvas or select nothing and all objects in the document outside the canvas will be deleted.'; alert('This operation produced no output. \n'+note); }else{ alert((elems.length-remainingElems.length) + " elements were deleted."); } } //try{ DeleteOutside(); //}catch(e){ alert([e, e.lineNumber, e.fileName].join("\n")) };